

package swa.e_store.userInterface;

import javax.swing.JOptionPane;
import swa.e_store.businessLogic.BL_Interface;
import swa.e_store.ENUM.EmployeeState;
import swa.e_store.businessLogic.BL_RemoteFacade;
//import swa.e_store.DTO.AuthenticationDTO
/**
 * LogicLogin class contains all logic needed for login-process.
 *
 * @author stefan schibig (stefan.schibig@stud.hslu.ch)
 */
public class LogicLogin {
    
    private GUILogin loginGUI;
    
    private BL_Interface bLogic;

    public LogicLogin(GUILogin loginGUI){
        this.loginGUI = loginGUI;
        this.bLogic = new BL_RemoteFacade();
    }

    /**
     * This method validates the login-data, checks the employee-state and
     * opens the appropriate user-interface.
     *
     * @param   login     the login-name
     * @param   password  the password entered
     */
    protected void login(String login, char[] password) throws Exception{
        if (bLogic.authenticate(login, new String(password)).getEmployeeState() == EmployeeState.NONE){
            JOptionPane.showMessageDialog(null, "Access denied!\nUnknown username or password.", "e-Store-Login failed", JOptionPane.ERROR_MESSAGE);
        } else{
            //open mainGUI
            GraphicalUI mainGui = new GraphicalUI(bLogic.authenticate(login, new String(password)).getEmployeeState());
            //close loginGUI
            loginGUI.setVisible(false);
            loginGUI.dispose();
        }
    }

}
